<%@ page contentType="text/html;charset=UTF-8"  %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title>加入我们</title>
    <link rel="stylesheet" href="../../admin/css/pintuer.css">
    <link rel="stylesheet" href="../../admin/css/admin.css">
    <script src="../../admin/js/jquery.js"></script>
    <script src="../../admin/js/pintuer.js"></script>
    <style>
        a{
            text-decoration: none;
        }
    </style>
</head>
<body>
<form method="post" action="">
    <div class="panel admin-panel">
        <div class="panel-head"><strong class="icon-reorder"> 留言管理</strong></div>
        <div class="padding border-bottom">
            <ul class="search">
                <li>
                    <a type="button"  class="button border-green" id="checkall" href="javascript:void(0)"><span class="icon-check"></span> 全选</a>
                    <a type="submit" class="button border-red" id="delselect" href="javascript:void(0)"><span class="icon-trash-o"></span> 批量删除</a>
                </li>
            </ul>
        </div>
        <table class="table table-hover text-center">
            <tr>
                <th width="120">ID</th>
                <th>姓名</th>
                <th>电话</th>
                <th>邮箱</th>
                <th width="25%">内容</th>
                <th width="120">留言时间</th>
                <th>操作</th>
            </tr>
            <script type="text/javascript">
                var i = 0;
                var ids = new Array();
            </script>
            <c:forEach items="${message.list}" var="mess">

                <tr>
                    <td><input type="checkbox" name="id[]" value="1"/>${mess.id}</td>
                    <td>${mess.name}</td>
                    <td>${mess.phone}</td>
                    <td>${mess.email}</td>
                    <td>${mess.message}</td>
                    <td>${mess.create_time}</td>
                    <td>
                        <div class="button-group">
                            <a class="button border-red" href="javascript:void(0)" onclick="return del(${mess.id})">
                                <span class="icon-trash-o"></span> 删除
                            </a>
                        </div>
                    </td>
                    <script type="text/javascript">
                        ids[i] = $("td").eq(0 + (7 * i)).text();
                        i ++;
                    </script>
                </tr>

            </c:forEach>
            <tr>
                <td colspan="7">
                    <div class="pagelist">
                        <c:if test="${message.pageNo != 1}">
                            <a style="text-decoration: none" href="${pageContext.request.contextPath}/MessageBoardServlet?method=adminGetMessageBoard&page=${message.pageNo - 1}">上一页</a>
                        </c:if>
                        <c:forEach begin="1" end="${message.totalPage}" var="i">
                            <a style="text-decoration: none" href="${pageContext.request.contextPath}/MessageBoardServlet?method=adminGetMessageBoard&page=${i}">${i}</a>
                        </c:forEach>
                        <c:if test="${message.pageNo != message.totalPage}">
                            <a style="text-decoration: none" href="${pageContext.request.contextPath}/MessageBoardServlet?method=adminGetMessageBoard&page=${message.pageNo + 1}">下一页</a>
                        </c:if>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</form>
<script type="text/javascript">

    function del(id) {
        if(confirm("您确定要删除吗?")) {
            location.href = '${pageContext.request.contextPath}/MessageBoardServlet?method=deleteMessageBoard&id=' + id;
        }
    }
    var check = new Array();
    var k = 0, v = 0;
    $("#checkall").click(function() {
        $("input[name='id[]']").each(function() {
            if (this.checked) {
                this.checked = false;
            }
            else {
                this.checked = true;
            }
        });
    })

    $("#delselect").click(function () {
        var Checkbox=false;
        $("input[name='id[]']").each(function() {
            if (this.checked==true) {
                Checkbox=true;
                check[v ++] = k;
            }
            k ++;
        });
        if (Checkbox) {
            var strids = '';
            var t = confirm("您确认要删除选中的内容吗？");
            if (t == false) { //不删除
                return false;
            }
            else { //删除
                for(i = 0; i < v; i ++) {
                    strids += ids[check[i]] + ',';
                }
                strids = strids.substring(0,strids.length - 1);
                location.href = "${pageContext.request.contextPath}/MessageBoardServlet?method=deleteMessageBoards&ids=" + strids;
            }
        }
        else{
            alert("请选择您要删除的内容!");
            return false;
        }
    })

</script>
</body>
</html>